/**
 * blank
 */

define(function (require) {
    var $ = require('jquery');
    var base = require('base');
    var com = require('./common');

    if(localStorage.getItem("lang")){
		var Lang = localStorage.getItem("lang")
	}else{
		var Lang = "zh_CN"
	}

	// 中文/英文转换
	if(Lang != "zh_CN"){
		$('#zxns_banner_text').html("Recruitment Center")
	}

    var leibie = '';
    var xingzhi = '';
    var xueli = '';
    var place = '';

    toshow = function(){
        $(this).next("li").slideToggle('fast').siblings(".j_c:visible").slideUp('fast');
        $(this).toggleClass("j_t_cur");
        $(this).siblings(".j_t_cur").removeClass("j_t_cur");
    }


    // 获取招聘岗位列表信息
    function getJob() {
        let data = {
            list_row:10,
            address:place,
            cate_id:leibie,
            nature_id:xingzhi,
            education_id:xueli
        }

        $.ajax(seajs.ajaxroot + "getJob", {
            headers:{
                'locale-language':Lang
            },
            type:'post',
            async:false,
            data:data,
            success:function(res){    
                console.log("getJob:", res)     
                let jobContent = Resume_submission = Job_responsibilities = Job_requirements = '';
                if(Lang != "zh_CN"){
                    jobContent = '<li class="first"><div class="_ut _t1">Recruitment positions</div><div class="_ut _t2">Job category</div><div class="_ut _t3">Job nature</div><div class="_ut _t4">education</div><div class="_ut _t5">Work location</div><div class="_ut _t6">Number of people</div><div class="_ut _t7">View Details</div></li>';
                    Resume_submission = "Resume submission";
                    Job_responsibilities = "Job responsibilities";
                    Job_requirements = "Job requirements";
                }else{
                    jobContent = '<li class="first"><div class="_ut _t1">招聘职位</div><div class="_ut _t2">职位类别</div><div class="_ut _t3">工作性质</div><div class="_ut _t4">学历</div><div class="_ut _t5">工作地点</div><div class="_ut _t6">人数</div><div class="_ut _t7">查看详情</div></li>';
                    Resume_submission = "简历投递";
                    Job_responsibilities = "岗位职责";
                    Job_requirements = "任职要求";
                }
                
                res.data.forEach(item=>{
                    jobContent += '<li class="j_t" onclick="toshow.call(this)">';
                    jobContent += '<div class="_un _t1">'+item.title+'</div>';
                    jobContent += '<div class="_un _t2">'+item.cate_name+'</div>';
                    jobContent += '<div class="_un _t3">'+item.nature_name+'</div>';
                    jobContent += '<div class="_un _t4">'+item.education_name+'</div>';
                    jobContent += '<div class="_un _t5">'+item.address+'</div>';
                    jobContent += '<div class="_un _t6">'+item.num+'</div>';
                    jobContent += '<div class="_un _t7"></div>';
                    jobContent += '</li>';
                    
                    jobContent += '<li class="j_c" >';
                    jobContent += '<div class="j_c_box">';
                    jobContent += '<div class="intro">';
                    jobContent += '<div class="text">';
                    jobContent += '<strong>【'+Job_responsibilities+'】</strong> ';
                    jobContent += '<p>'+item.description+'</p>';
                    jobContent += '<strong>【'+Job_requirements+'】</strong>';
                    jobContent += '<p>'+item.content+'</p>';
                    jobContent += '</div>';
                    jobContent += '<div class="job_btn"> <a  class="_btn _btn1 " onclick="submitResume()">'+Resume_submission+'</a></div>';
                    jobContent += '</div></div></li>';
                                    
                })
                $('#jobContent').html(jobContent)
            }
        });
    }



    (function () {
        // 获取岗位参数信息
        $.ajax(seajs.ajaxroot + "getJobParams", {
            type: 'post',
            headers:{
                'locale-language':Lang
            },
            async:false,
            success:function(res){
                console.log("getJobParams:", res)
                let JobParams = res.data;

                let jobCateDataList = '<option value="">- 职位类别 -</option>';
                JobParams.jobCateData.forEach((item,index)=>{
                    jobCateDataList += '<option value="'+item.id+'">'+item.title+'</option>'
                })
                $('#leibie').html(jobCateDataList)

                let xingzhiList = '<option value="">- 工作性质 -</option>';
                JobParams.natureData.forEach(item=>{
                    xingzhiList += '<option value="'+item.id+'">'+item.title+'</option>';
                })
                $('#xingzhi').html(xingzhiList)

                let xueliList = '<option value="">- 学历 -</option>';
                JobParams.educationData.forEach(item=>{
                    xueliList += '<option value="'+item.id+'">'+item.title+'</option>';
                })
                $('#xueli').html(xueliList)

                let placeList = '<option value="">- 工作地点 -</option>';
                JobParams.jobAddressData.forEach(item=>{
                    placeList += '<option value="'+item+'">'+item+'</option>';
                })
                $('#place').html(placeList)


            }
        })
        getJob();
    })();





    $("form").submit(function(){
        console.log("点提交了")

        getJob();
        
        return false;
    })
    // function submit_form(){
    //     console.log("提交数据了")
    //     // ajax
    //     return false;
    // }

    // 下拉
    require('select');
    $('#leibie').select({
        callback: function (val, txt) {
            console.log("类别", val)
            leibie = val;
        }
    })
    $('#xingzhi').select({
        callback: function (val, txt) {
            xingzhi = val;
        }
    })
    $('#xueli').select({
        callback: function (val, txt) {
            xueli = val;
        }
    })
    $('#place').select({
        callback: function (val, txt) {
            place = val;
        }
    })


    // let $j_t = $(".j_t");
    // $("#jobContent").on('click', $j_t,function(){
    //     console.log("好用了")
    //     console.log("点击.j_t")
    //     $j_t.next("li").slideToggle('fast').siblings(".j_c:visible").slideUp('fast');
    //     $j_t.toggleClass("j_t_cur");
    //     $j_t.siblings(".j_t_cur").removeClass("j_t_cur");
    // })

    // $(".j_t").click(function () {
    //     console.log($(this))
    //     $(this).next("li").slideToggle('fast').siblings(".j_c:visible").slideUp('fast');
    //     $(this).toggleClass("j_t_cur");
    //     $(this).siblings(".j_t_cur").removeClass("j_t_cur");
    // });
    // $('.job_list01 .content .j_t:first').trigger('click');




    submitResume = function(){
        $('#upload').click();
    }
         
    $('#upload').click(function () {
        $('#upload').val('');
    });

    $('#upload').on('change', function(){
        
        var fd = new FormData();
        fd.append('file', $('#upload')[0].files[0]);

        // 上传文件
        $.ajax(seajs.ajaxroot + "submitResume", {
            type: 'post',
            headers:{
                'locale-language':Lang
            },
            data:fd,

            // 不修改 Content-Type 属性，使用 FormData 默认的 Content-Type 值
            contentType: false,
            // 不对 FormData 中的数据进行 url 编码，而是将 FormData 数据原样发送到服务器
            processData: false,
            success: function(res) {
               alert(res.msg)
            }    

        })


    });



        if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
            var swiper = new Swiper('.swiper-container', {
            loop: true,
            slidesPerView: 1,
            pagination: {
                el: '.swiper-pagination',
            },
            })
        } else {
            var swiper = new Swiper('.swiper-container', {
                autoplay: {
                delay: 5000,
                disableOnInteraction: false,
                },
                speed: 700,
                allowTouchMove: false,
                lazy: {
                loadPrevNext: true,
                loadPrevNextAmount: 3,
                },
                centeredSlides: true,
                spaceBetween: 50,
                slidesOffsetBefore: 40,
                loop: true,
                slidesPerView: 'auto',
                on: {
                slideChangeTransitionEnd: function () {
                    this.slides.transition(this.params.autoplay.delay + this.params.speed).transform('translate3d(-60px, 0, 0)');
                },
                slideChangeTransitionStart: function () {
                    this.slides.transition(this.params.speed).transform('translate3d(0, 0, 0)');
                },
                },
                pagination: {
                el: '.swiper-pagination',
                clickable: true,
                renderBullet: function (index, className) {
                    return '<div class="' + className + '"><span></span><i></i></div>';
                },
                },
                navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
                },
            });
          
  
          window.onresize = function () {
            swiper.update();
          }

        }






});